package com.ptswitch.material.pages.contract.supplier;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.ptswitch.material.model.contract.ContractSupplier;
import com.ptswitch.material.pages.base.PageBase;
import com.ptswitch.material.service.ContractSupplierService;
import com.ptswitch.material.util.security.PermissionUtil;

public class CreateSupplier extends PageBase {
    @Inject
    private ContractSupplierService contractSupplierSer;
    @Property
    private ContractSupplier supplier;
    @InjectPage
    private ListSupplier listSupplier;

    @OnEvent(value = EventConstants.ACTIVATE)
    Object init() {
        checkPermitted(PermissionUtil.ContractCreate);
        supplier = new ContractSupplier();
        return null;
    }

    @OnEvent(value = EventConstants.SUCCESS)
    Object createContract() {
        checkPermitted(PermissionUtil.ContractCreate);
        contractSupplierSer.save(supplier);
        //send email,now node
        //hlog
//		hlog(HlogConstants.addContract, contract);
        return listSupplier.withInit(50, 1);
    }
}
